package com.taoym.voucher.xcx.controller;

import com.taoym.voucher.common.response.Response;
import com.taoym.voucher.xcx.entity.dto.XcxUpdateUserInfoDTO;
import com.taoym.voucher.xcx.entity.dto.XcxUserLoginDTO;
import com.taoym.voucher.xcx.entity.vo.XcxGetChiefProfitVO;
import com.taoym.voucher.xcx.entity.vo.XcxGetUserInfoDetailVO;
import com.taoym.voucher.xcx.entity.vo.XcxGetUserInfoVO;
import com.taoym.voucher.xcx.service.XcxUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/6/8 8:52
 * @desc 用户控制器
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户控制器")
@Validated
public class XcxUserInfoController {

    @Autowired
    private XcxUserInfoService xcxUserInfoService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Response<Integer> userLogin(@RequestBody @Valid XcxUserLoginDTO data) {
        return Response.success(xcxUserInfoService.userLogin(data));
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/detail")
    public Response<XcxGetUserInfoDetailVO> getUserInfoDetail() {
        return Response.success(xcxUserInfoService.getUserInfoDetail());
    }

    @ApiOperation("修改用户信息")
    @PostMapping("/update")
    public Response<Integer> updateUserInfo(@RequestBody @Valid XcxUpdateUserInfoDTO data) {
        return Response.success(xcxUserInfoService.updateUserInfo(data));
    }

    @ApiOperation("团队列表")
    @GetMapping("/list")
    public Response<List<XcxGetUserInfoVO>> listUsers() {
        return Response.success(xcxUserInfoService.getUserInfos());
    }

    @ApiOperation("团长收益信息")
    @GetMapping("/chief/fee")
    public Response<XcxGetChiefProfitVO> chiefProfit() {
        return Response.success(xcxUserInfoService.chiefProfit());
    }
}
